/*
    Coder: Dzlua
    Email: 505544956@qq.com
    Time : 2017/06/23
*/

#include <iostream>
#include <memory>
#include <vector>
#include <string>
using namespace std;

#include "pkghead.h"

int main(int argc, char** argv)
{
    cout << "hello world!" << endl;

    const char data[] = {
                                       0x16,0x03,0x01,0x02,0x00,0x01,0x00,0x01,0xfc,0x03
        ,0x03,0x72,0x09,0xb8,0x34,0xa0,0xe1,0x04,0x92,0xcd,0x37,0x87,0x22,0x4e,0xc0,0x51
        ,0xe9,0xad,0x7e,0x25,0xbc,0xb9,0x11,0x7f,0xa5,0x89,0x34,0x2b,0x63,0xfc,0x91,0x4b
        ,0xbc,0x20,0xf4,0x11,0xf4,0x47,0xc0,0x31,0xaa,0x07,0x7d,0xa3,0xe1,0x33,0x2d,0x83
        ,0x20,0xd3,0xc3,0x18,0xac,0x54,0x9e,0x2f,0x24,0x4f,0x0a,0x49,0x49,0xcd,0x61,0xe2
        ,0x8d,0x81,0x00,0x22,0x7a,0x7a,0x13,0x01,0x13,0x02,0x13,0x03,0xc0,0x2b,0xc0,0x2f
        ,0xc0,0x2c,0xc0,0x30,0xcc,0xa9,0xcc,0xa8,0xc0,0x13,0xc0,0x14,0x00,0x9c,0x00,0x9d
        ,0x00,0x2f,0x00,0x35,0x00,0x0a,0x01,0x00,0x01,0x91,0xba,0xba,0x00,0x00,0xff,0x01
        ,0x00,0x01,0x00,0x00,0x00,0x00,0x12,0x00,0x10,0x00,0x00,0x0d,0x73,0x70,0x32,0x2e
        ,0x62,0x61,0x69,0x64,0x75,0x2e,0x63,0x6f,0x6d,0x00,0x17,0x00,0x00,0x00,0x23,0x00
        ,0xb0,0x4b,0x3d,0x03,0x23,0xb1,0x1d,0x42,0x86,0x8c,0x6e,0x17,0xbd,0x27,0x4b,0xba
        ,0xdd,0x3c,0xdf,0x51,0x15,0x3e,0xfa,0x8c,0x43,0x1a,0x61,0xf6,0x6a,0xa8,0xe4,0xd4
        ,0x1e,0x71,0xde,0x15,0x81,0x5b,0xe9,0xbf,0xe9,0xdd,0xc0,0xa2,0xfe,0x70,0xe4,0xbf
        ,0xb4,0x9c,0x40,0xae,0x81,0xdd,0x74,0x3d,0x3e,0xaf,0x89,0x4c,0x25,0xb2,0xca,0x73
        ,0x34,0xba,0xc1,0x48,0xe2,0x11,0x8c,0xa9,0xee,0x97,0xdb,0x29,0x99,0x80,0xeb,0x4b
        ,0x7b,0x10,0x09,0xa9,0x07,0xdd,0x31,0x43,0x29,0x1c,0x32,0xe0,0xbd,0x6c,0x18,0x0b
        ,0xd8,0x1a,0xf0,0x29,0xe4,0x8f,0xc9,0xb2,0x4a,0x73,0x92,0xe3,0xed,0x51,0x27,0x46
        ,0xaa,0x40,0x09,0xf8,0x5f,0x85,0xf5,0x4e,0xc5,0x02,0xb2,0x69,0xa0,0x1f,0x07,0x56
        ,0x8e,0xa1,0x5d,0xb2,0x8e,0x70,0x72,0x1f,0x82,0xae,0x84,0xca,0x10,0xb7,0xfb,0x76
        ,0xc7,0xf7,0x4c,0xe7,0xdd,0x9c,0x02,0x93,0xf2,0x4d,0x5b,0x8a,0xea,0xe5,0xf2,0x2b
        ,0x6b,0x11,0x03,0x51,0x53,0x48,0x3a,0x82,0xc1,0xdb,0x41,0xac,0xe9,0x60,0xad,0xee
        ,0x71,0x00,0x0d,0x00,0x14,0x00,0x12,0x04,0x03,0x08,0x04,0x04,0x01,0x05,0x03,0x08
        ,0x05,0x05,0x01,0x08,0x06,0x06,0x01,0x02,0x01,0x00,0x05,0x00,0x05,0x01,0x00,0x00
        ,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x10,0x00,0x0e,0x00,0x0c,0x02,0x68,0x32,0x08
        ,0x68,0x74,0x74,0x70,0x2f,0x31,0x2e,0x31,0x75,0x50,0x00,0x00,0x00,0x0b,0x00,0x02
        ,0x01,0x00,0x00,0x28,0x00,0x2b,0x00,0x29,0x0a,0x0a,0x00,0x01,0x00,0x00,0x1d,0x00
        ,0x20,0x21,0xc5,0xb3,0xe0,0x76,0x2f,0x57,0xe3,0xce,0x95,0xc7,0xed,0xf9,0xd0,0x07
        ,0xe5,0x17,0xfb,0x4c,0xef,0xe9,0xf6,0xdb,0xe7,0x8b,0xe6,0xdb,0xcf,0x43,0x77,0x56
        ,0x70,0x00,0x2d,0x00,0x02,0x01,0x01,0x00,0x2b,0x00,0x0b,0x0a,0xaa,0xaa,0x7f,0x12
        ,0x03,0x03,0x03,0x02,0x03,0x01,0x00,0x0a,0x00,0x0a,0x00,0x08,0x0a,0x0a,0x00,0x1d
        ,0x00,0x17,0x00,0x18,0x00,0x18,0x00,0x04,0x00,0x0a,0x01,0x02,0x3a,0x3a,0x00,0x01
        ,0x00,0x00,0x15,0x00,0x16,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
        ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    };

    HttpsPkg hsp;
    bool bok = hsp.Init(data);
    if (!bok) {
        cout << "init error" << endl;
        return 0;
    }

    size_t aaa = hsp._high4bit(0xfc);
    size_t bbb = hsp._low4bit(0xfc);

    HttpsPkg::sData dat = hsp.GetVer();

    size_t len = hsp.GetPkgLen();

    dat = hsp.GetClientHello();

    const char* type = hsp.GetHandShakeType();

    len = hsp.GetClientHelloLen();

    dat = hsp.GetClientHelloVer();

    //
    HttpsPkg::sData ext = hsp.GetExtension();

    dat = hsp.FindExtention(ext, HttpsPkg::EXT_SERVER_NAME);

    auto sn = hsp.ParserSerName(dat);
    cout << "server name is : " << sn->name << endl;

    dat = hsp.FindExtention(ext, HttpsPkg::EXT_RENEGOTIATION);

    dat = hsp.FindExtention(ext, HttpsPkg::EXT_MASTER_SECRET);

    dat = hsp.FindExtention(ext, HttpsPkg::EXT_SESSION_TICKET);

    cout << "-------------------" << endl;
    cout << "server name is : ";
    cout << HttpsPkg::GetServerName(data) <<endl;
    cout << "-------------------" << endl;

    return 0;
}
